<template>
	<view>
		<head-navbar :back="true">
			<view>
				<text>{{title}}</text>
			</view>
		</head-navbar>
		<view class="content">
			<view class="box">
				<view class="title">
					<view class="text">转账数量</view>
				</view>
				<view class="select"><input v-model="zuanshiNum" type="digit" placeholder="请输入转账数量" /></view>
				<view class="down">
					<view class="left">{{tip}}：{{money}}</view>
					<view class="right" v-if="$store.state.dataBody.diamondTaxRate != 0 && this.type == 1">手续费：{{Math.floor($store.state.dataBody.diamondTaxRate*zuanshiNum*100)/100}}</view>
					<view class="right" v-if="$store.state.dataBody.yuanDiamondTaxRate != 0 && this.type == 2">手续费：{{Math.floor($store.state.dataBody.yuanDiamondTaxRate*zuanshiNum*100)/100}}</view>
					<view class="right" v-if="$store.state.shopDataBody.balanceTaxRate != 0 && this.type == 3">手续费：{{Math.floor($store.state.shopDataBody.balanceTaxRate*zuanshiNum*100)/100}}</view>
				</view>
				<view class="title title2">
					<view class="text">收款账号</view>
				</view>
				<view class="select"><input v-model="subUserCode" type="text" placeholder="请输入收款账号" /></view>
			</view>
			<button class="btn" @click="submit">确认</button>
		</view>
		<ssPaymentPassword ref="paymentPassword" :mode="mode" :digits="6" :forget="false" @submit="submitHandle" />
	</view>
</template>

<script>
	import ssPaymentPassword from '@/components/sanshui-payment-password'
	import * as api from '@/api/user/money.js';
	import * as index from '@/api/user/index.js';
	export default{
		components:{
		    ssPaymentPassword
		},
		data() {
			return {
				mode:1,
				type:null,
				title:'',
				tip:'',
				money:'',
				subUserCode:'',
				zuanshiNum:'',
				reg:/^\d+(\.\d{0,2})?$/
			}
		},
		onLoad(option) {
			this.type = option.type
			this.money = option.money
			switch(this.type){
				case '1':
				this.title = '钻石转账'
				this.tip = '当前钻石余额'
				break;
				case '2':
				this.title = '原钻转账'
				this.tip = '当前原钻余额'
				break;
				case '3':
				this.title = '余额转账'
				this.tip = '当前余额'
				break;
				default:
				break;
			}
		},
		methods:{
			submit(){
				// if(this.type == 1){
					if(this.zuanshiNum == ''){
						uni.showToast({
							title:'转账数量不能为0',
							icon:'none'
						})
						return
					}
					if(!this.reg.test(this.zuanshiNum)){
						uni.showToast({
							title:'转账数量最多两位小数',
							icon:'none'
						})
						return
					}
					if(this.subUserCode == ''){
						uni.showToast({
							title:'收款账号不能为空',
							icon:'none'
						})
						return
					}
					this.$refs.paymentPassword.modalFun('show');
				// }
			},
			submitHandle(e){
				if(this.type == 1){
					this.diamondTransfer(e.value)
				}else if(this.type == 2){
					this.yuanDiamondTransfer(e.value)
				}else if(this.type == 3){
					this.balanceTransfer(e.value)
				}
			},
			diamondTransfer(value){
				api.diamondTransfer({request:{diamond:this.zuanshiNum,password:value,subUserCode:this.subUserCode}}).then(res=>{
					uni.showToast({
						title:'转账成功',
						icon:'none'
					})
					this.money = this.money - this.zuanshiNum
					this.subUserCode = ''
					this.zuanshiNum = ''
					this.$api.prePage().status = 'loading'
					this.$api.prePage().list = []
					this.$api.prePage().pageNo = 1
					this.$api.prePage().moneyNumber = this.money
					this.$api.prePage().getRecordList()
				})
			},
			yuanDiamondTransfer(value){
				api.yuanDiamondTransfer({request:{yuanDiamond:this.zuanshiNum,password:value,subUserCode:this.subUserCode}}).then(res=>{
					uni.showToast({
						title:'转账成功',
						icon:'none'
					})
					this.money = this.money - this.zuanshiNum
					this.subUserCode = ''
					this.zuanshiNum = ''
					this.$api.prePage().status = 'loading'
					this.$api.prePage().list = []
					this.$api.prePage().pageNo = 1
					this.$api.prePage().moneyNumber = this.money
					this.$api.prePage().getRecordList()
				})
			},
			balanceTransfer(value){
				index.balanceTransfer({amount:this.zuanshiNum,password:value,userCode:this.subUserCode}).then(res=>{
					uni.showToast({
						title:'转账成功',
						icon:'none'
					})
					this.money = this.money - this.zuanshiNum
					this.subUserCode = ''
					this.zuanshiNum = ''
					this.$api.prePage().status = 'loading'
					this.$api.prePage().list = []
					this.$api.prePage().pageNo = 1
					this.$api.prePage().moneyNumber = this.money
					this.$api.prePage().getRecordList()
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
  .content{
	  padding: 30rpx;
	  .box{
		  background: #FFFFFF;
		  border-radius: 20rpx;
		  padding: 30rpx;
		  .title{
			  display: flex;
			  align-items: center;
			  .text{
				  flex: none;
				  font-size: 36rpx;
				  margin-right: 20rpx;
			  }
		  }
		  .title2{
			  margin-top: 40rpx;
		  }
		  input{
		  	   font-size: 26rpx;
		  }
		  .select{
			  margin-top: 30rpx;
			  color: #9A9A9A;
			  font-size: 24rpx;
			  padding-bottom: 20rpx;
			  border-bottom: 1rpx solid #f4f4f4;
		  }
		  .down{
			  margin-top: 30rpx;
			  font-size: 26rpx;
			  display: flex;
			  justify-content: space-between;
			  .left{
				  color: #FF5C02;
			  }
			  .right{
				   color: #9A9A9A;
			  }
		  }
	  }
	  .btn{
		  background: #FF5C02;
		  border-radius: 100rpx;
		  color: #FFFFFF;
		  margin-top: 30rpx;
	  }
  }
</style>
